<template>
  <a-layout id="app-layout-sider">
    <a-layout-sider
      v-model="collapsed"
      theme="light"
      class="layout-sider"
    >
      <div class="logo">
        <img class="pic-logo" src="~@/assets/logo.png">
      </div>
      <a-menu class="menu-item" theme="light" mode="inline" :default-selected-keys="['jsonFormat']" :default-open-keys="['tools']" @click="menuHandle">
        <template v-for="item in menus">
          <a-menu-item v-if="!item.children" :key="item.key">
            <a-icon :type="item.icon" />
            <span>{{ item.title }}</span>
          </a-menu-item>
          <sub-menu v-else :key="item.key" :menu-info="item" />
        </template>
      </a-menu>
      <a-button type="primary" class="collapsed-btn" :class="collapsed ? 'narrow':'wide'" @click="toggleCollapsed">
        <a-icon :type="collapsed ? 'menu-unfold' : 'menu-fold'" />
      </a-button>
    </a-layout-sider>
    <a-layout>
      <a-layout-content class="layout-content">
        <router-view />
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script>
 import SubMenu from './SubMenu.vue';
 import { Icon } from 'ant-design-vue';
const Fonts = Icon.createFromIconfontCN({
     scriptUrl: '/js/iconfont.js'
 })
export default {
  name: 'AppSider',
  components: {
    'sub-menu': SubMenu,
    Fonts
  },
  data() {
    return {
      collapsed: false,
      menus: [
        {
          key: 'tools',
          title: '工具',
          icon: 'setting',
          children: [
            {
              key: 'jsonFormat',
              title: 'json工具',
              icon: 'icon-json',
              pageName: 'jsonFormat',
              params: {}
            },
            {
              key: 'xmlFormat',
              title: 'xml工具',
              icon: 'icon-xml',
              pageName: 'xmlFormat',
              params: {}
            }
          ]
        },
        {
          key: 'other',
          title: '其他',
          icon: 'smile',
          children: []
        }
      ]
    };
  },
  created () {},
  mounted () {
    this.menuHandle({key: 'jsonFormat'})
  },
  methods: {
    menuHandle (item) {
      console.info(item)
      this.$router.push({ name: item.key, params: item.params})
    },
    toggleCollapsed () {
      this.collapsed = !this.collapsed
    }
  },
};
</script>
<style lang="less" scoped>
// 嵌套
#app-layout-sider {
  height: 100%;
  .logo {
    border-bottom: 1px solid #e8e8e8;
  }
  .pic-logo {
    height: 32px;
    //background: rgba(139, 137, 137, 0.2);
    margin: 10px;
  }
  .layout-sider {
    border-top: 1px solid #e8e8e8;
    border-right: 1px solid #e8e8e8;
  }
  .menu-item {
    .ant-menu-item {
      background-color: #fff;
      margin-top: 0px;
      margin-bottom: 0px;
      padding: 0 0px !important;
    }
  }
  .layout-content {
    // background-color: #fff;
  }
  .collapsed-btn {
    position: fixed;
    bottom: 0;
    left: 0;
  }
  .wide {
    width: 200px;
  }
  .narrow {
    width: 80px;
  }
  .ant-layout-sider{
    transition:all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1)
  }
}
</style>
